import { config } from "./config"
/* 封装wx.request */
export const request = (url, data = {}, method='get') => {
  return new Promise((resolve, reject) => {
    wx.request({
        url:`${config.host}/${url}`,
        method,
        data,
        header:{
          cookie:wx.getStorageSync('cookie')
        },
        success: res => {
            // if(data.isLogin === true){
            //   const cookie = res.cookies.find(cookie => cookie.startsWith('MUSIC_U'))
            //   try{
            //     wx.setStorageSync('cookie', cookie)
            //   }catch(e){
            //     console.log(e, '保存cookie失败')
            //   } 
            // }
            resolve(res.data)
        },
        fail: err => {
          console.log('出错啦')
            reject({
              err,
              msg:'请求错误'
            })
        }
    }
    )
  })
}
